﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text;
using PlugNT.Common;
using PlugNT.Custom;
using PlugNT.Cms.Core;
using PlugNT.Cms.Model;
using PlugNT.Cms.BLL;
using PlugNT.Cms.Page;

namespace PlugNT.Cms.Web.Admin.Pre_Create
{
    public partial class EditReplaceTemplet : AdminPage
    {
        private Templet curTemplet = new Templet();
        private string currpostfix = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            //权限检测
            this.CheckPower();

            if (!IsPostBack)
            {
                currpostfix = (Request.QueryString["currpostfix"] == null) ? WebConfig.TablePostfix : Request.QueryString["currpostfix"].Trim();

            }
        }



        protected void Button_update_Click(object sender, EventArgs e)
        {
            string oldstring = txtOldString.Text.Trim();
            string newstring = txtNewString.Text.Trim();
            if (oldstring != "" && newstring != "")
            {
                DataTable dt = curTemplet.GetBingList(currpostfix);
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        int id = (int)dr["id"];
                        string indexfile = dr["indexfile"].ToString();
                        string listfile = dr["listfile"].ToString();
                        string showfile = dr["showfile"].ToString();

                        bool tmpflag = false;
                        if (indexfile != "")
                        {
                            indexfile = indexfile.Replace(oldstring, newstring);
                            tmpflag = true;
                        }
                        if (listfile != "")
                        {
                            listfile = listfile.Replace(oldstring, newstring);
                            tmpflag = true;
                        }
                        if (showfile != "")
                        {
                            showfile = showfile.Replace(oldstring, newstring);
                            tmpflag = true;
                        }
                        if (tmpflag)
                        {
                            curTemplet.ReplaceTemplet(id, indexfile, listfile, showfile);
                        }
                    }
                    Response.Redirect("BindTemplet.aspx");
                }
                else
                {
                    Response.Redirect("../Message.aspx?message=<b>[修改模板路径]</b>--失败！" + "&z=no");
                }
            }
            else
            {
                Response.Redirect("../Message.aspx?message=<b>[修改模板路径]</b>--失败,原字符串或新字符串中不能为空！" + "&z=no");
            }
        }

    }
}

 